package com.base.app_core.service.user.impl;

import android.view.View;

import com.alibaba.android.arouter.launcher.ARouter;
import com.base.app_core.App;
import com.base.app_core.base.BaseView;
import com.base.app_core.ioc.module.BaseModule;
import com.base.app_core.model.Paginated;
import com.base.app_core.service.user.LoginCallback;
import com.base.app_core.service.user.model.User;
import com.base.app_core.util.AppConstants;

import javax.inject.Inject;


/**
 * 用来代理OnClickListener,点击时先判断是否登录,如果没有登录,跳去登录页
 * Created by xiangheng.song on 2017/3/7.
 */

public class OnClickListenerForceLogin implements View.OnClickListener, LoginCallback,BaseView {

    private View view;
    private View.OnClickListener listener;
    @Inject
    User user;
    public OnClickListenerForceLogin(View view, View.OnClickListener listener){
        this.view = view;
        this.listener = listener;
        App.getApp().getAppComponent().plus(new BaseModule(this)).inject(this);
    }

    @Override
    public void onClick(View v) {
        if(user!=null&&user.getLogin()){
            listener.onClick(v);
            return;
        }
        App.lastCallback = this;
        ARouter.getInstance().build(AppConstants.ROUTEURI.LOGIN).navigation();
//        Routers.open(App.getContext(), "kachemama://login");
    }

    @Override
    public void onLoginSuccess() {
        listener.onClick(view);
    }

    @Override
    public void setState(int state) {

    }

    @Override
    public <T> void notifyData(T object, Class tClass, Paginated paginated) {

    }
    @Override
    public void notifyError(String errorCode, String content) {

    }
}
